package com.briup.app02.web.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.app02.bean.ProductCategory;
import com.briup.app02.service.IProductCategoryService;
import com.briup.app02.utils.Message;
import com.briup.app02.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Validated
@RestController
@RequestMapping("/productCategory")
@Api(description="产品分类")
public class ProductCategoryController {
	@Autowired
	private IProductCategoryService productCategoryService;
	
	@ApiOperation(value="查询产品分类信息")
	@GetMapping("query")
	@ApiImplicitParams({
        @ApiImplicitParam(name="name",value = "分类名称",paramType = "query"),
	})
	public Message query(String name) {
		List<ProductCategory>list=productCategoryService.query(name);
		return MessageUtil.success(list);
	}
	
	//分页查询
	@ApiOperation(value = "分页查询产品分类")
	@ApiImplicitParams({
		@ApiImplicitParam(name="page",value = "当前页",paramType = "query",required = true),
        @ApiImplicitParam(name="pageSize",value = "每页大小",paramType = "query",required = true),
        @ApiImplicitParam(name="name",value = "产品名称",paramType = "query"),
	})
	@GetMapping("pageQuery")
	public Message pageQuery(int page,int pageSize,String name) {
		List<ProductCategory>list=productCategoryService.pageQuery(page, pageSize, name);
		return MessageUtil.success(list);
	}
	
	@ApiOperation(value = "通过id删除产品分类")
	@GetMapping("deleteById")
	@ApiImplicitParams({
		@ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
	})
	public Message deleteById( Long id) {

		productCategoryService.deleteById(id);
		return MessageUtil.success("删除成功");
	}
	
	@ApiOperation(value = "保存或更新产品分类信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name="id",value = "主键",paramType = "form"),
        @ApiImplicitParam(name="name",value = "产品分类",paramType = "form",required = true),
        @ApiImplicitParam(name="icon",value = "图标",paramType = "form"),
        @ApiImplicitParam(name="num",value = "序号",paramType = "form"),
        @ApiImplicitParam(name="parentId",value = "父编号",paramType = "form"),
	})
	@PostMapping("saveOrUpdate")
	public Message saveOrUpdate(ProductCategory productCategory) {
		productCategoryService.saveOrUpdate(productCategory);
		return MessageUtil.success("更新成功");
	}
	
	/*@GetMapping("findAll")
	@ApiOperation("查询所有产品分类")
	public List<ProductCategory> findAll(){
		return productCategoryService.findAll();
	}
	
	@GetMapping("findById")
	@ApiOperation("根据id查询产品分类")
	@ApiImplicitParam(name ="id",value = "产品分类id",dataType = "long",paramType = "query",required = true)
	public ProductCategory findById(long id) {
		return productCategoryService.findById(id);
		
	}
	
	@PostMapping("saveOrUpdate")
	@ApiOperation(value="保存或更新",notes = "id为空是保存否则是更新")
	public String saveOrUpdate(ProductCategory productCategory){
		productCategoryService.saveOrUpdate(productCategory);
		return("操作成功！");
		
	}
	
	@DeleteMapping("deleteById")
	@ApiOperation("根据id删除产品分类")
	@ApiImplicitParam(name="id",value = "栏目id",dataType = "long",paramType = "query",required = true)
	public String deleteById(long id) {
		productCategoryService.deleteById(id);
		return("删除成功");
	}*/
	
}
